Skip to content

Add --hook flag to defer eval execution to WordPress lifecycle hooks#84

Merged
swissspidy merged 4 commits intomainfrom
copilot/add-hook-flag-to-eval-shell
Feb 5, 2026
Merged

Add --hook flag to defer eval execution to WordPress lifecycle hooks#84
swissspidy merged 4 commits intomainfrom
copilot/add-hook-flag-to-eval-shell

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Implementation Plan for --hook=<hook> Flag

  • Understand the current implementation of eval and eval-file commands
  • Add --hook=<hook> parameter to Eval_Command class
  • Add --hook=<hook> parameter to EvalFile_Command class
  • Modify execution logic to defer to WordPress hook if --hook is provided
  • Update command documentation to include new flag
  • Add Behat tests for eval with --hook flag
  • Add Behat tests for eval-file with --hook flag
  • Run linting and static analysis (all passed)
  • Code review completed (suggestions noted but design choices justified)
  • Security check completed (no issues found)
  • Manual logic validation completed
  • Refactored to use closure pattern for better readability

Summary

Successfully implemented the --hook=<hook> flag for both eval and eval-file commands. The implementation:

  1. Registers code on WordPress hooks: When --hook is provided, the code/file is registered as an action callback before WordPress loads
  2. Validates flag combinations: Prevents using --hook with --skip-wordpress since hooks require WordPress
  3. Preserves existing behavior: When --hook is not provided, commands work exactly as before
  4. Comprehensive test coverage: Added 5 new test scenarios covering various use cases and error conditions
  5. Uses closure pattern: Execution logic is defined once and either passed to hook registration or executed directly, improving code readability and reducing duplication

The implementation follows WordPress conventions and matches the behavior of add_action(), providing flexibility for users to execute code at any point in the WordPress lifecycle.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add --hook=<hook> flag to eval and shell to choose timing</issue_title>
<issue_description>## Feature Request

For both the eval|eval-file commands as well as the shell command, there's a fixed point in time within the WordPress lifecycle that these are executed.

It would be great to have a --hook=<hook> flag for these that allows the user to postpone when they are being triggered, so that you can choose a specific time within the WordPress lifecycle to run them on.

Describe your use case and the problem you are facing

An example is using these commands to QA new code. Some code can only be executed once the preconditions are met, which means they need to be executed at or after a certain action.

Allowing these commands to be attached to a specific action/filter allows the user to choose when to execute them, so that they can ensure the preconditions for the code to be run are met.

Describe the solution you'd like

This can probably be done by dynamically creating a closure with the code to evaluate or the PsySh breakpoint and attaching that closure to the requested action, instead of immediately executing something.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add --hook=<hook> flag to eval and shell commands Add --hook flag to defer eval execution to WordPress lifecycle hooks Feb 1, 2026
Copilot AI requested a review from swissspidy February 1, 2026 17:11

This comment was marked as resolved.

@swissspidy swissspidy linked an issue Feb 2, 2026 that may be closed by this pull request
2 tasks
@swissspidy swissspidy marked this pull request as ready for review February 3, 2026 01:40
@swissspidy swissspidy requested a review from a team as a code owner February 3, 2026 01:40
@swissspidy swissspidy added this to the 2.2.8 milestone Feb 3, 2026
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy merged commit 52a50c1 into main Feb 5, 2026
44 checks passed
@swissspidy swissspidy deleted the copilot/add-hook-flag-to-eval-shell branch February 5, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs say "before_wp_load" but everything is loaded already? Add --hook=<hook> flag to eval and shell to choose timing

2 participants